package com.wetool.wechat.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.wetool.wechat.entity.MinaAccountRelation;
import com.wetool.wechat.feign.MinaFeignClient;
import com.wetool.wechat.feign.WechatOpenPlatformFeignClient;
import com.wetool.wechat.jpa.MinaAccountRelationRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.data.jpa.repository.Modifying;

@Service
@Transactional(readOnly = true)
public class MinaService {
	
    @Autowired
    private MinaFeignClient minaFeignClient;
    
    @Autowired
    MinaAccountRelationRepo minaAccountRelationRepo;
	 /**
     * 创建微信小程序用户
     *
     * @return MinaAccountRelation
     */
    @Transactional
    @CacheEvict(cacheNames="secondlevels",allEntries = true)
	public void save(MinaAccountRelation entity) {
    	
		minaAccountRelationRepo.save(entity);}
	 /**
	 * 查询微信小程序用户 By mianOpenid
	 *
	 * @return MinaAccountRelation
	 */
    @Transactional
    @CacheEvict(cacheNames="secondlevels",allEntries = true)
	public MinaAccountRelation findByMinaOpenid(String minaOpenid) {
	    return minaAccountRelationRepo.findByMinaOpenid(minaOpenid);
	}
    /**
     * 查询小程序用户 By thirdSession
     * @param thirdSession
     * @return MinaAccountRelation
     */
    @Transactional
    @CacheEvict(cacheNames="secondlevels",allEntries = true)
	public  MinaAccountRelation findByThirdSession(String thirdSession) {
		return minaAccountRelationRepo.findByThirdSession(thirdSession);
	}
    /**
     * 更新小程序用户thirdSession值 By thirdSession
     * @param thirdSession
     * 
     */
    @Transactional
    @Modifying
    @CacheEvict(cacheNames="secondlevels",allEntries = true)
	public void updateThirdSession(String thirdSession) {
		minaAccountRelationRepo.updateThirdSession(thirdSession);
	}
	public Object minaFeignClient(String jSCODE) {
		// TODO Auto-generated method stub
		return null;
	}
}
